package com.ruoyi.quartz.task;

import com.ruoyi.system.domain.EDiscountInfo;
import com.ruoyi.system.domain.vo.TradeLedger;
import com.ruoyi.system.service.IEDiscountInfoService;
import com.ruoyi.system.service.TicketExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    @Autowired
    TicketExchangeService ticketExchangeService;
    @Autowired
    IEDiscountInfoService ieDiscountInfoService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }

    public void discountInfo(String cookie,String dseSessionId,String startDate,String endDate,String dsePageId)
    {
        Date date=new Date();
        Map<String, String> map= ticketExchangeService.getPublicPara(cookie,dseSessionId,date);
        Integer  begNum=1;
        if(StringUtils.isNotEmpty(dsePageId)){
            begNum=begNum+Integer.parseInt(dsePageId)*200;
        }
        List<String> tradeLedgers=ticketExchangeService.getTradeLedger(cookie,dseSessionId,map.get("branchId"),map.get("memberCode"),startDate,endDate,date,begNum);
        tradeLedgers.stream().forEach(cdno -> {
            EDiscountInfo eDiscountInfo = new EDiscountInfo();
            eDiscountInfo.setTicketCode(cdno);
            if(ieDiscountInfoService.selectEDiscountInfoList(eDiscountInfo).size()==0){
                String name= ticketExchangeService.queryBedcinfo(cookie,dseSessionId,map.get("branchId"),cdno);
                if(StringUtils.isNotEmpty(name)){
                    eDiscountInfo.setDiscountApplicantName(name);
                    ieDiscountInfoService.insertEDiscountInfo(eDiscountInfo);
                }
            }
        });
        System.out.println("执行有参方法：cookie=" + cookie+"dseSessionId="+dseSessionId);
    }

}
